package com.example.shinelon.startproject_202;




        import android.support.v7.app.AppCompatActivity;

        import android.os.Bundle;

        import android.view.View;

        import android.widget.Button;

        import android.widget.EditText;

        import android.widget.TextView;

        import com.example.shinelon.startproject_202.bean.WeatherInfo;
        import com.example.shinelon.startproject_202.iface.WeatherListener;
        import com.example.shinelon.startproject_202.model.Weather51Model;
        import com.example.shinelon.startproject_202.model.WeatherModel;


public class MainActivity extends AppCompatActivity implements WeatherListener, View.OnClickListener{



    private EditText etcity;

    private Button btnfind1,btnfind2;

    private TextView tvcityname;





    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        init();

    }

    private void init(){

        etcity=(EditText)findViewById(R.id.editText);

        btnfind1=(Button)findViewById(R.id.button);

        btnfind2=(Button)findViewById(R.id.button2);

        tvcityname=(TextView)findViewById(R.id.textView4);

        btnfind1.setOnClickListener(this);

        btnfind2.setOnClickListener(this);

    }





    public void onResponse(WeatherInfo weatherInfo) {

        if(weatherInfo!=null){

            tvcityname.setText("温度"+weatherInfo.getCity()+"SD"+weatherInfo.getSD()+"湿度"+weatherInfo.getTemp()+"WD"+weatherInfo.getWD()+"WS"+weatherInfo.getWS());

        }

    }



    public void onFail(String msg) {

        tvcityname.setText(msg);

    }



    public void onClick(View v) {

        switch(v.getId()){

            case R.id.button:

                System.out.println("---button1 was clicked");

                WeatherModel weatherModel=new WeatherModel();

                weatherModel.getWeather(etcity.getText().toString(),this);

                break;

            case R.id.button2:

                System.out.println("---buutton2 was clicked");

                Weather51Model weather51Model=new Weather51Model();

                weather51Model.getWeather(etcity.getText().toString(),this);

                break;

        }

    }

}